package com.spring.mvc.http.client;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;


public class HttpClientDemo {

	public static void main(String[] args) {
		HttpClient client=new DefaultHttpClient();
		HttpGet httpGet=new HttpGet("http://www.baidu.com");
		
		System.out.println(httpGet.getURI());
		try {
			HttpResponse response=client.execute(httpGet);
			HttpEntity entity=response.getEntity();
			System.out.println("---------------------------------------");
			System.out.println(response.getStatusLine());
			if(entity!=null){
				System.out.println("Response Context Length:"+entity.getContentLength());
			}
			System.out.println("---------------------------------------");
			
			httpGet.abort();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			client.getConnectionManager().shutdown();
		}
	}
}
